﻿using System;

namespace RDS.Core
{
    /// <summary>
    /// 对象池接口定义
    /// </summary>
    public interface IObjectPoolable<T>
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="objType">缓存的对象的类型</param>
        /// <param name="cArgs">缓存对象的构造参数</param>
        /// <param name="minNum"></param>
        /// <param name="maxNum"></param>
        /// <returns></returns>
        bool Initialize(Type objType, object[] cArgs, int minNum, int maxNum);
        /// <summary>
        /// 对象有效性判断
        /// </summary>
        /// <returns></returns>
        bool IsValidate();
        /// <summary>
        /// 借出
        /// </summary>
        /// <returns></returns>
        T Rent();
        /// <summary>
        /// 归还
        /// </summary>
        /// <param name="objHashCode"></param>
        void Return(int objHashCode);
        /// <summary>
        /// 
        /// </summary>
        /// <param name="item"></param>
        void Return(T item);
        /// <summary>
        /// 资源释放
        /// </summary>
        void Dispose();

        /// <summary>
        /// 最小对象数量
        /// </summary>
        int MinObjCount { get; }
        /// <summary>
        /// 最大对象数量
        /// </summary>
        int MaxObjCount { get; }
        /// <summary>
        /// 当前对象数量
        /// </summary>
        int CurObjCount { get; }
        /// <summary>
        /// 处理对象数量
        /// </summary>
        int IdleObjCount { get; }

        event CallBackObjPool PoolShrinked;
        event CallBackObjPool MemoryUseOut; //内存分配失败
    }

    public delegate void CallBackObjPool();

}
